<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table{
            border-spacing: 0;
            border: 1px solid grey;
        }
        th, td{
            border-bottom: 1px solid lightgrey;
            padding: 10px 20px;
        }
        caption{
            border: 1px solid grey;
            border-bottom: none;
            font-size: 32px;
            line-height: 60px;
        }
        tbody tr:hover td{
            background-color: #f0f0f0;
        }
    </style>
</head>
<script src="./jquery.js"></script>
<body>
    <table>
        <caption>未来七天天气预报</caption>
        <thead>
            <tr>
                <th>日期</th>
                <th>天气情况</th>
                <th>温度</th>
                <th>风力</th>
                <th>空气等级</th>
                <th>建议</th>
            </tr>
        </thead>
        <tbody id="tab"></tbody>
    </table>
</body>
<script>
            function request(option){
            var def = $.Deferred();
            if(!option || !option.url){
                throw Error('url is undefine');
            }
            var _config = {
                type: 'get',
                dataType: 'JSON',
                success: function(data){
                    def.resolve(data);
                },
                error: function(a,b,err){
                    def.reject(err);
                }
            }

            $.extend(_config, option, true);
            $.ajax(_config);

            return def.promise();
        }

        var option = {
            url: 'https://v1.yiketianqi.com/api?unescape=1&version=v9&appid=13955891&appsecret=K1xspFHc'
        }

        request(option).then(function(data){
            console.log(data);
            var str = '';
            for(var d of data.data){
                str += '<tr>';
                    str += '<td>' + d.date +  '</td>' ;
                    str += '<td>' + d.wea +  '</td>' ;
                    str += '<td>最低温度：' + d.tem2 + '℃, 最高温度：' + d.tem1 +  '℃</td>' ;
                    str += '<td>' + d.win_speed +  '</td>' ;
                    str += '<td>' + d.air_level +  '</td>' ;
                    str += '<td>' + d.air_tips +  '</td>' ;
                str += '</tr>';
            }

            $('#tab').html(str);
        }, function(err){
            console.log(err);
        });

</script>
</html>